package com.leviassaf.androidbasics;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class CoolMenu extends ListActivity {
	
	String[] arrStrClasses = {"StartingPoint", "TextPlay",
			"Email", "Camera",
			"Data", "Graphics",
			"GFXSurface", "Voice",
			"SoundStuff", "Slider",
			"Tabs", "WebBrowser",
			"Flipper", "SharedPrefs",
			"InternalData", "ExternalData",
			"SqlLite", "MyTextToSpeech"
			};
	Intent intent;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		//61
		//remove the title containing notification area
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		//set full screen
		getWindow().setFlags(
			WindowManager.LayoutParams.FLAG_FULLSCREEN, 
			WindowManager.LayoutParams.FLAG_FULLSCREEN
		);
		
		//19
		setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrStrClasses));
	
		this.setTitle(String.format("%s-%s", this.getTitle().toString(), this.getClass().getSimpleName()));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		//21
		String strClickedClassName = arrStrClasses[position]; 
		//20
		Class classClicked = null;
		try{
			classClicked = Class.forName(
				String.format(
					"com.leviassaf.speaktranslation.%s", 
					strClickedClassName
				)
			);
		}
		catch (ClassNotFoundException e){
			
		}
		Intent intent = new Intent(this, classClicked);
		startActivity(intent);
	}

	//51
	@Override
	public boolean onCreateOptionsMenu(android.view.Menu menu) {
		// TODO Auto-generated method stub
		super.onCreateOptionsMenu(menu);
		MenuInflater mnuinflaterBlowUp = getMenuInflater();
		mnuinflaterBlowUp.inflate(R.menu.cool_menu, menu);
		return true;
	}


	//52
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()){
		case R.id.mnuitmAboutUs:
			intent = new Intent("com.leviassaf.speaktranslation.ABOUT");
			startActivity(intent);
			break;
		case R.id.mnuitmPreferences:
			intent = new Intent("com.leviassaf.speaktranslation.PREFS");
			startActivity(intent);
			break;
		case R.id.mnuitmExit:
			finish();
			break;
		}
		return false;
	}
}
